package com.goozao.vc.project;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.goozao.core.controller.GoozaoSimpleController;
import com.ruoyi.common.core.domain.AjaxResult;

/**
 * 项目管理类定制化程序入口
 */
@Controller
@RequestMapping("/" + ProjectController.PREFIX)
public class ProjectController extends GoozaoSimpleController {

	private static final Logger logger = LoggerFactory.getLogger(ProjectController.class);

    public static final String PREFIX = "vc";
    
    @Autowired
    private IProjectService projectService;
    
    @PostMapping("/project/importSchedule")
    @ResponseBody
    public AjaxResult importSchedule(String oid, MultipartFile file, boolean updateSupport) throws Exception {
        try {
        	logger.info(file.getName());
        	return AjaxResult.success(projectService.importSchedule(oid, file.getOriginalFilename(), file.getInputStream()));
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return error(e.getMessage());
        }
    }

    @PostMapping("/project/importSchedule2")
    @ResponseBody
    public AjaxResult importSchedule2(String oid, MultipartFile file, boolean updateSupport) throws Exception {
        try {
        	logger.info(file.getName());
        	return AjaxResult.success(projectService.importSchedule2(oid, file.getOriginalFilename(), file.getInputStream()));
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return error(e.getMessage());
        }
    }
    
    @PostMapping("/project/exportSchedule2")
    @ResponseBody
    public AjaxResult exportSchedule(String oid) throws Exception {
    	try {
    		logger.info("导出计划任务，计划的唯一标识:{}", oid);
    		return AjaxResult.success(projectService.exportSchedule2(oid));
    	} catch (Exception e) {
    		logger.error(e.getMessage(), e);
    		return error(e.getMessage());
    	}
    }
    
    @Override
    public String getPrefix() {
        return PREFIX;
    }

}
